<?php
/**
 * @package admin
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 *  $Id: featured.php 16339 2010-05-24 09:57:04Z ajeh $
 */

  require('includes/application_top.php');



  $action = (isset($_GET['action']) ? $_GET['action'] : '');

  if (zen_not_null($action)) {
    switch ($action) {
      case 'update':
      	if(1){
      	  if($_POST['category_id']!=''){
      	  	 $categories_type_upate = $db->Execute(" select ct.categories_type
                                          from " . TABLE_CATEGORY_TYPE . " ct 
                                          where ct.categories_id = '" . $_POST['category_id'] . "'");
      	  	 
      	  	  $categories_type_upate_string='';
      	  	  for($i=0;$i<4;$i++){
                 $categories_type_upate_string.=$_POST['type'.$i];
              }
      	  	 if(!$categories_type_upate->EOF){
      	  	 	//如果 有已经有数据则更新

      	  	 	$categories_type_upate_result=$db->Execute(" update " . TABLE_CATEGORY_TYPE . " ct
      	  	 	                                             set ct.categories_type='".$categories_type_upate_string ."'
                                                             where ct.categories_id = '" . $_POST['category_id'] . "'");      	 
      	  	 	if($categories_type_upate_result){
      	  	 		echo zen_redirect(basename($PHP_SELF));
      	  	 	}else{
      	  	 		
      	  	 	}	 	
      	  	 }else{
      	  	 	//如果没有数据则插入新数据
       	  	 	$categories_type_upate_result=$db->Execute(" insert into " . TABLE_CATEGORY_TYPE . "(categories_id,categories_type)
       	  	 	                                             values(" . $_POST['category_id'] . ",'".$categories_type_upate_string ."')
       	  	 	                                           ");
      	  	 	                                                	 
      	  	 	if($categories_type_upate_result){
      	  	 	   echo zen_redirect(basename($PHP_SELF));
      	  	 		//echo('更新成功');
      	  	 	}	     	  	 	
      	  	 }
      	  }
      	}
      break;
    }
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript">
  <!--
  function init()
  {
    cssjsmenu('navbar');
    if (document.getElementdyId)
    {
      var kill = document.getElementdyId('hoverJS');
      kill.disabled = true;
    }
  }
  // -->
</script>
</head>
<body onload="init()">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); 
//echo zen_draw_form('languages', basename($PHP_SELF), '', 'get');
?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="700" cellspacing="2" cellpadding="2">
      <tr>
            <td class="pageHeading">顶级栏目</td>
            <td class="pageHeading">二级栏目类型</td>
            <td class="pageHeading" >三级栏目类型</td>
            <td class="pageHeading">四级栏目类型</td>
            <td class="pageHeading">五级栏目类型</td>
            <td class="pageHeading">操作</td>
      </tr>

<!-- body_eof //-->

<?php 


$categories_query = "select c.categories_id, cd.categories_name
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd 
                             where c.parent_id = 0
                             and c.categories_id = cd.categories_id
                             and cd.language_id='" . (int)$_SESSION['languages_id'] . "'
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";
      
// echo  $categories_query ;
$categories = $db->Execute($categories_query);



while (!$categories->EOF)  {
echo '<tr>';
echo zen_draw_form('form', basename($PHP_SELF).'?action=update', '', 'post');
echo zen_draw_hidden_field('category_id',$categories->fields['categories_id']);

$categories_type_array=array();
$categories_type_array[] = array('id' => '0', 'text' => '未指定');	   
$categories_type_array[] = array('id' => 'b', 'text' => 'Brand');	    
$categories_type_array[] = array('id' => 's', 'text' => 'Series');	    
$categories_type_array[] = array('id' => 'm', 'text' => 'Model');	    
$categories_type_array[] = array('id' => 'p', 'text' => 'Products type');	                  
   
   
  $categories_type_query = " select ct.categories_type
                             from " . TABLE_CATEGORY_TYPE . " ct 
                             where ct.categories_id = '" . $categories->fields['categories_id'] . "'";
  $categories_type = $db->Execute( $categories_type_query);
  if (!$categories_type->EOF)  {
    $categories_type_string= $categories_type->fields['categories_type'];
    
    echo '<td>'.$categories->fields['categories_name'].'</td>';
    
    for($i=0;$i<4;$i++){
        echo '<td>'.zen_draw_pull_down_menu('type'.$i,$categories_type_array,$categories_type_string[$i]).'</td>';		
    };
    echo '<td><input name="submit"  type="submit"  value="submit"/></td>';
  }else{
  	echo '<td>'.$categories->fields['categories_name'].'</td>';
  	echo '<td>'.zen_draw_pull_down_menu('type0',$categories_type_array,'0').'</td>';
  	echo '<td>'.zen_draw_pull_down_menu('type1',$categories_type_array,'0').'</td>';
  	echo '<td>'.zen_draw_pull_down_menu('type2',$categories_type_array,'0').'</td>';
   	echo '<td>'.zen_draw_pull_down_menu('type3',$categories_type_array,'0').'</td>';
    echo '<td><input name="submit"  type="submit"  value="submit"/></td>';
  }
echo '</form></tr>';	
  $categories->MoveNext();
}




?>

</table>

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
